package com.example.easyexcel.controller;

import com.example.easyexcel.listener.ExcelListener;
import com.example.easyexcel.model.ok.AliEmailModel;
import com.example.easyexcel.model.ok.AliEmailUserResplModel;

import java.util.List;
import java.util.stream.Collectors;

import static com.alibaba.excel.EasyExcelFactory.read;

public class OkExcelEmailController {
    public static void main(String[] args) {
//        readExcel_AliSendToUserAllErrorCode();
//        readExcel_AliSendToUser();
        readExcel_sendToAli();
    }
    public static void readExcel_sendToAli(){
        String fileName = "C:\\Users\\hp\\Desktop\\阿里邮箱错误码.xlsx";
        ExcelListener<AliEmailModel> excelListener = new ExcelListener<>();
        read(fileName, AliEmailModel.class, excelListener).sheet("发送阿里推送接口返回错误码").doRead();
        List<AliEmailModel> dataList = excelListener.getDataList();
        List<AliEmailModel> collect = dataList.stream().filter(x -> x.getCode() != null).collect(Collectors.toList());
//        System.out.println(JSON.toJSONString(dataList));
        for (AliEmailModel jm  : collect) {
            String code = jm.getCode().replace(" ","_").replace(".","").toUpperCase();
            String prefix = "E";
            prefix = prefix + "_" + code;
            String str = prefix + "(\"" + jm.getCode() + "\",\"" +  jm.getMsg() + "\"),";
            System.out.println(str);
        }
    }

    public static void readExcel_AliSendToUser(){
        String fileName = "C:\\Users\\hp\\Desktop\\阿里邮箱错误码.xlsx";
        ExcelListener<AliEmailModel> excelListener = new ExcelListener<>();
        read(fileName, AliEmailModel.class, excelListener).sheet("阿里发送用户邮箱返回错误码").doRead();
        List<AliEmailModel> dataList = excelListener.getDataList();
        List<AliEmailModel> collect = dataList.stream().filter(x -> x.getMsg() != null).collect(Collectors.toList());
//        System.out.println(JSON.toJSONString(dataList));
        for (AliEmailModel jm  : collect) {
            String code = jm.getCode().replace(" ","_").replace(".","").toUpperCase();
            String prefix = "E";
            prefix = prefix + "_" + code;
            String str = prefix + "(\"" + jm.getCode() + "\",\"" +  jm.getMsg() + "\"),";
            System.out.println(str);
        }
    }

    public static void readExcel_AliSendToUserAllErrorCode(){
        String fileName = "C:\\Users\\hp\\Desktop\\阿里邮箱错误码.xlsx";
        ExcelListener<AliEmailUserResplModel> excelListener = new ExcelListener<>();
        read(fileName, AliEmailUserResplModel.class, excelListener).sheet("用户返回结果总类型").doRead();
        List<AliEmailUserResplModel> dataList = excelListener.getDataList();
        List<AliEmailUserResplModel> collect = dataList.stream().filter(x -> x.getMsg() != null).collect(Collectors.toList());
//        System.out.println(JSON.toJSONString(dataList));
        for (AliEmailUserResplModel jm  : collect) {
            String code = jm.getCode().replace(" ","_").replace(".","").toUpperCase();
            String prefix = "E";
            prefix = prefix + "_" + code;
            String str = prefix + "(\"" + jm.getCode() + "\",\"" +  jm.getMsg() + "\"),";
            System.out.println(str);
        }
    }
}
